﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Linq.Expressions;
using System.Web;
using Campus.Entities;

namespace CampusSite.Models
{
    
    public class ConvocatoriaRepository : IConvocatoriaRepository
    {
        public CampusSiteContext context{get; set;}

        public ConvocatoriaRepository()
        {
            context = new CampusSiteContext();
        }
        public ConvocatoriaRepository(CampusSiteContext context)
        {
            this.context = context;
        }    

        public IQueryable<Convocatoria> All
        {
            get { return context.Convocatorias; }
        }
        
        public IQueryable<Convocatoria> AllIncluding(params Expression<Func<Convocatoria, object>>[] includeProperties)
        {
            IQueryable<Convocatoria> query = context.Convocatorias;
            foreach (var includeProperty in includeProperties) {
                query = query.Include(includeProperty);
            }
            return query;
        }
     


        public Convocatoria Find(int id)
        {
            return context.Convocatorias.Find(id);
        }

        public void InsertOrUpdate(Convocatoria convocatoria)
        {
            if (convocatoria.ConvocatoriaId == default(int))
            {
                // New entity
                context.Convocatorias.Add(convocatoria);
            }
            else
            {
                // Existing entity
                context.Entry(convocatoria).State = EntityState.Modified;
            }
        }

        //public void Delete(int id)
        //{
        //    var escuela = context.Escuelas.Find(id);
        //    context.Escuelas.Remove(escuela);
        //}

        public void Save()
        {
            context.SaveChanges();
        }

        public void Dispose()
        {
            context.Dispose();
        }

    }

         public interface IConvocatoriaRepository : IDisposable
    {
        IQueryable<Convocatoria> All { get; }
        IQueryable<Convocatoria> AllIncluding(params Expression<Func<Convocatoria, object>>[] includeProperties);
        Convocatoria Find(int id);
        void InsertOrUpdate(Convocatoria convocatoria);
        //void Delete(int id);
        void Save();        
    }
}